﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.ComponentModel;
using System.Windows.Controls;
using GameLogic.Controls;

namespace Bubbles
{
    public partial class BubblesGame : UserControl, IGameFeatures
    {
        public BubblesGame()
        {
            InitializeComponent();

            _playground.GameFinished += (s,e) =>
                {
                    if (GameOver != null)
                    {
                        GameOverEventArgs args = new GameOverEventArgs();

                        GameOver(this, args);
                    }
                };

            _playground.BubblesRemoved += (s, e) =>
                {
                    OnScoresChanged(e.BubbleCount * e.BubbleCount);
                };
            
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                // Init Trick
                Settings.Level = Settings.Level;
            }
        }

        public void Start()
        {
            _playground.Opacity = 1;
            _playground.Start();
        }

        public void Stop()
        {

        }

        public void OnScoresChanged(int scores)
        {
            if (ScoresChanged != null)
            {
                ScoresChangedEventArgs args = new ScoresChangedEventArgs();
                args.Scores = scores;
                ScoresChanged(this, args);
            }
        }

        public event EventHandler<ScoresChangedEventArgs> ScoresChanged;
        public event EventHandler<LivesChangedEventArgs> LivesChanged;

        public void Pause()
        {

        }

        public void Resume()
        {

        }

        public bool IsTimeBased
        {
            get { return false; }
        }

        public bool IsLifeBase
        {
            get { throw new NotImplementedException(); }
        }

        public string GameName
        {
            get { return "Bubbles"; }
        }

        public bool IsLifeBased
        {
            get { return false; }
        }

        public TimeSpan GameDuration
        {
            get { return new TimeSpan(0,0,0); }
        }

        public event EventHandler<GameOverEventArgs> GameOver;

        public string DeveloperName
        {
            get { return "Oliver Scheer"; }
        }

        public string CompanyName
        {
            get { return "Microsoft Deutschland GmbH"; }
        }

        public string Description
        {
            get { return string.Empty; }
        }

        public Uri SettingsPage
        {
            get { return new Uri("/SettingsPage.xaml", UriKind.Relative); }
        }

        public event EventHandler<TimeChangedEventArgs> TimeChanged;


        public void OnLivesChanged(int lives)
        {

        }
    }
}
